﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Net;
using System.Text;
using System.IO;
/// <summary>
/// Summary description for WebTool
/// </summary>
public class WebTool
{
	public WebTool()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    #region "Method"
        public static string getWebContent(string pUrl)
        {
            string retContent = "";
            if (pUrl != "")
            {
                try
                {
                    //System.Net.WebClient myClient = new System.Net.WebClient();
                    //myClient.Encoding = System.Text.Encoding.UTF8;
                    //System.IO.Stream myStream = myClient.OpenRead(pUrl);
                    //System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myStream, System.Text.Encoding.UTF8, true);


                    UTF7Encoding enc = new UTF7Encoding();
                    WebClient browser = new WebClient();
                    retContent = enc.GetString(browser.DownloadData(pUrl));

                    //F1
                    //string NewLine;
                    //loop through the stream and put the output in the textbox.
                    //while ((NewLine = myStreamReader.ReadLine()) != null)
                    //    txOutput += NewLine + "\r\n";

                    //txOutput = myStreamReader.ReadToEnd();
                    //myStream.Close();
                }
                catch (Exception ex)
                {
                   TLog.WriteErr("WebTool:getWebContent", ex.Message);
                }
            }
            return retContent;
        }

    public static string getWebClient(string pUrl)
    {
        string retContent = "";
        HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(pUrl);
        WebRequestObject.UserAgent = ".NET Framework/2.0";
        //WebRequestObject.Referer = "http://www.techcombank.com.vn/Desktop.aspx/Thong-tin-ty-gia/Ty-gia";
        WebResponse Response = WebRequestObject.GetResponse();

        // Open data stream:
        Stream WebStream = Response.GetResponseStream();

        // Create reader object:
        StreamReader Reader = new StreamReader(WebStream);

        // Read the entire stream content:
        retContent = Reader.ReadToEnd();

        // Cleanup
        Reader.Close();
        WebStream.Close();
        Response.Close();
        return retContent;
    }
    #endregion
}
